package wservice;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class UriMapping {

	private static Log log = LogFactory.getLog(UriMapping.class); 
	
	private UriMapping() {
	}

	private Object synobj = new Object();
	
	private static UriMapping instance = new UriMapping();

	public static UriMapping getInstance() {
		return instance;
	}

	private Map<String, Action> mapping = new HashMap<String, Action>();
	
	public void regist(String path, Action action) {
		synchronized(synobj) {
			if(log.isInfoEnabled()) {
				if(mapping.containsKey(path)) {
					log.info(path  + " has exists!!! ");
				}
			}
			mapping.put(path, action);
		}
	}
	
	public void regist(Path path, Action action) {
		synchronized(synobj) {
			if(log.isInfoEnabled()) {
				if(mapping.containsKey(path)) {
					log.info(path  + " has exists!!! ");
				}
			}
			mapping.put(path.toString(), action);
		}
	}
	
	/**
	 * 区分大小写
	 * @param path
	 * @return
	 */
	public Action getActionByPath(String path) {
		synchronized(synobj) {
			if(!mapping.containsKey(path)) {
				log.error(path + " is not have action mapping.");
				return null;
			}
			return mapping.get(path);
		}
	}
	
}
